package sr.myserver.controller;

import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sr.myserver.entity.SysParams;
import sr.myserver.service.SysParamsService;
import sr.myserver.vo.SelectData;
import sr.myserver.vo.common.Basic;
import sr.myserver.vo.common.PageRequest;
import sr.myserver.vo.common.PageResponse;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/sysparams")
@Api(tags = "参数信息")
public class SysParamsController {

    @Autowired
    SysParamsService sysParamsService;

    @GetMapping("/{id}")
    @Operation(summary = "指定ID获取数据")
    public SysParams get(@PathVariable("id") String id) {
        return sysParamsService.get(id);
    }

    @PostMapping
    @Operation(summary = "添加数据")
    public Basic.Response post(@RequestBody SysParams entity) {
        return sysParamsService.add(entity);
    }

    @PutMapping("/edit")
    @Operation(summary = "指定ID修改数据")
    public Basic.Response put(@RequestBody SysParams entity) {
        return sysParamsService.update(entity);
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "指定ID删除数据")
    public Basic.Response delete(@PathVariable("id") String id) {
        return sysParamsService.deleteById(id);
    }


    @PutMapping
    @Operation(summary = "分页列表数据")
    public PageResponse<SysParams> queryTables(@RequestBody PageRequest request) {
        return sysParamsService.queryTables(request);
    }

    @PostMapping("/getall")
    @Operation(summary = "查询全部系统参数")
    public Map<String, List<SelectData>> getAll() {
        return sysParamsService.getAll();
    }

}

